import { showSuccessToast, showFailToast, showConfirmDialog } from 'vant';
import BusinessStore from '@/stores/business';
import AddressStore from '@/stores/address';
import CartStore from '@/stores/cart';

const success = (message,onClose = () => {},duration = 1500) =>
{
    showSuccessToast({
        message,
        onClose,
        duration
    });
}

const fail = (message,onClose = () => {},duration = 1500) =>
{
    showFailToast({
        message,
        onClose,
        duration
    });
}

export default {
    install(app)
    {
        // 初始化
        const BusinessStoreInit = BusinessStore();
        const AddressStoreInit = AddressStore();
        const CartStoreInit = CartStore();

        // 提取store数据是一个ref定义响应式
        const { business } = storeToRefs(BusinessStoreInit);
        const { address } = storeToRefs(AddressStoreInit);
        const { cart } = storeToRefs(CartStoreInit);

        app.config.globalProperties.$success = success;
        app.config.globalProperties.$fail = fail;
        app.config.globalProperties.$business = business;
        app.config.globalProperties.$address = address;
        app.config.globalProperties.$cart = cart;
        app.config.globalProperties.$confirm = showConfirmDialog;
    }
}